using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour {

    public Vector3 posicaoFinal;
    private float distance;
    private float minDistance;
    private GameObject player;

    public float speed;
	
	private DadosIniciais dadosIniciais;

	void Start () {
        minDistance = 0.5f;
        player = GameObject.FindGameObjectWithTag(Tags.player);
		dadosIniciais = GameObject.Find("Dados").GetComponent<DadosIniciais>();
	}
	
	void FixedUpdate () {
        transform.position = Vector3.MoveTowards(transform.position, posicaoFinal, speed);

        if (transform.position == posicaoFinal)
            Destroy(gameObject);

        distance = Vector3.Distance(transform.position, player.transform.position);

        if (distance <= minDistance)
        {
            dadosIniciais.reborn(true);
            Destroy(gameObject);
        }
	}
}